#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
结算账单查询使用示例

@author liaochangyi
@since 2025-01-25
"""

import os
import sys

# 添加项目根目录到Python路径，确保能够导入jlpay包
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))

from examples.base_example import BaseExample
from jlpay.services.openmerch.bill.bill_service import BillService
from jlpay.model.openmerch.bill.settle_bill_query import SettleBillQueryRequest


class SettleBillQueryExample(BaseExample):
    """结算账单查询示例类"""

    def __init__(self):
        """初始化示例类"""
        super().__init__("examples.openmerch.bill.settle_bill_query")
        self.service = BillService(self.config)

    def build_settle_bill_query_request(self):
        """构建结算账单查询请求"""
        request = SettleBillQueryRequest()

        # 设置请求参数
        request.set_merch_no("849584358120018")
        request.set_start_busi_date("2024-07-01")
        request.set_end_busi_date("2024-07-02")
        request.set_start_settle_date("2024-07-01")
        request.set_end_settle_date("2024-07-02")
        request.set_pay_status("1")

        return request

    def demo(self):
        """执行结算账单查询示例"""
        self.logger.info("开始执行结算账单查询示例")

        # 创建结算账单查询请求
        request = self.build_settle_bill_query_request()

        # 发送请求
        response = self.send_request_and_handle_response(
            self.service.settle_bill_query,
            "结算账单查询",
            request
        )

        # 处理响应结果
        if response and response.is_success():
            self.logger.info(f"响应报文：{response.to_dict()}")

        self.logger.info("结算账单查询示例执行完毕")


if __name__ == "__main__":
    example = SettleBillQueryExample()
    example.demo() 